
package com.tools.cleanmaster.model.db;

import android.database.Cursor;

import com.tools.cleanmaster.model.db.annotations.TrashDBAnnotation;
import com.tools.cleanmaster.model.db.annotations.Type;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CacheTrashBean {

    @TrashDBAnnotation(name = "a", type = Type.IntData)
    public int id;

    @TrashDBAnnotation(name = "b", type = Type.StringData)
    public String pkgName;

    @TrashDBAnnotation(name = "c", type = Type.StringData)
    public String filePath;

    @TrashDBAnnotation(name = "d", type = Type.StringData)
    public String description;

    @TrashDBAnnotation(name = "e", type = Type.StringData)
    public String alertInfo;

    @TrashDBAnnotation(name = "f", type = Type.IntData)
    public int contentType;

    @TrashDBAnnotation(name = "g", type = Type.IntData)
    public int deleteLevel;

    @TrashDBAnnotation(name = "h", type = Type.StringData)
    public String itemName;//短描

    @TrashDBAnnotation(name = "i", type = Type.LongData)
    public long fileId;

    @TrashDBAnnotation(name = "j", type = Type.IntData)
    public int mediaType;

    @TrashDBAnnotation(name = "k", type = Type.IntData)
    public int lid = 1;//语种

    public long itemNameID;//短描ID,之前是自增长,现在是与服务器同步

    public int localLid=1;//当前语种id

    public String localName;//当前语种描述

    public String rootPath;

    /**
     * 更新时间
     */
    public long updateTime;

    /**
     * 路径来源０本地1 云端
     */
    public int sourceType;


    public CacheTrashBean() {

    }

    public static List<CacheTrashBean> fromCursor(Cursor cursor) {
        if (cursor == null || cursor.getCount() == 0) {
            return Collections.emptyList();
        }

        final int idIndex = cursor.getColumnIndexOrThrow("a");
        final int pkgNameIndex = cursor.getColumnIndexOrThrow("b");
        final int filePathIndex = cursor.getColumnIndexOrThrow("c");
        final int descriptionIndex = cursor.getColumnIndexOrThrow("d");
        final int alertInfoIndex = cursor.getColumnIndexOrThrow("e");
        final int contentTypeIndex = cursor.getColumnIndexOrThrow("f");
        final int deleteLevelIndex = cursor.getColumnIndexOrThrow("g");
        final int itemNameIndex = cursor.getColumnIndexOrThrow("h");
        final int fileIdIndex = cursor.getColumnIndexOrThrow("i");
        final int mediaTypeIndex = cursor.getColumnIndexOrThrow("j");
        final int lidIndex = cursor.getColumnIndexOrThrow("k");

        ArrayList<CacheTrashBean> beans = new ArrayList<CacheTrashBean>(cursor.getCount());
        while (cursor.moveToNext()) {
            CacheTrashBean bean = new CacheTrashBean();
            bean.id = cursor.getInt(idIndex);
            bean.pkgName = cursor.getString(pkgNameIndex);
            bean.filePath = cursor.getString(filePathIndex);
            bean.description = cursor.getString(descriptionIndex);
            bean.alertInfo = cursor.getString(alertInfoIndex);
            bean.contentType = cursor.getInt(contentTypeIndex);
            bean.deleteLevel = cursor.getInt(deleteLevelIndex);
            bean.itemName = cursor.getString(itemNameIndex);
            bean.fileId = cursor.getLong(fileIdIndex);
            bean.mediaType = cursor.getInt(mediaTypeIndex);
            bean.lid = cursor.getInt(lidIndex);
            beans.add(bean);
        }

        return beans;
    }
}
